package org.hot100_6.leetcode21;

import org.algorithm.List.ListNode;
import org.utils.ListNode.ListNodeUtils;

public class Solution {

    public static void main(String[] args) {
        int [] test  = {1,2,4};
        int [] test2 = {1,3,4};
        ListNode listNode = ListNodeUtils.createListNode(test);
        ListNode listNode1 = ListNodeUtils.createListNode(test2);
        ListNode listNode2 = mergeTwoLists(listNode, listNode1);
    }

    public static ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        ListNode head= new ListNode(-1);
        ListNode res = head;

        while (list1!=null && list2!=null){
            if (list1.val > list2.val){
                res.next = list2;
                list2 = list2.next;
            }else {
                res.next = list1;
                list1 = list1.next;
            }
            res = res.next;
        }

        if (list1==null){
            res.next = list2;
        }

        if (list2 == null){
            res.next = list1;
        }


        return head.next;
    }
}
